package com.ruoyi.project.channel.productOrderInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.productOrderInfo.domain.ProductOrderInfo;
import com.ruoyi.project.channel.productOrderInfo.service.IProductOrderInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 产品订单信息操作处理
 * 
 * @author CAIN
 * @date 2021-01-09
 */
@Controller
@RequestMapping("/channel/productOrderInfo")
public class ProductOrderInfoController extends BaseController
{
    private String prefix = "channel/productOrderInfo";
	
	@Autowired
	private IProductOrderInfoService productOrderInfoService;
	
	@RequiresPermissions("channel:productOrderInfo:view")
	@GetMapping()
	public String productOrderInfo()
	{
	    return prefix + "/productOrderInfo";
	}
	
	/**
	 * 查询产品订单列表
	 */
	@RequiresPermissions("channel:productOrderInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProductOrderInfo productOrderInfo)
	{
		startPage();
        List<ProductOrderInfo> list = productOrderInfoService.selectProductOrderInfoList(productOrderInfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出产品订单列表
	 */
	@RequiresPermissions("channel:productOrderInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductOrderInfo productOrderInfo)
    {
    	List<ProductOrderInfo> list = productOrderInfoService.selectProductOrderInfoList(productOrderInfo);
        ExcelUtil<ProductOrderInfo> util = new ExcelUtil<ProductOrderInfo>(ProductOrderInfo.class);
        return util.exportExcel(list, "productOrderInfo");
    }
	
	/**
	 * 新增产品订单
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存产品订单
	 */
	@RequiresPermissions("channel:productOrderInfo:add")
	@Log(title = "产品订单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProductOrderInfo productOrderInfo)
	{		
		return toAjax(productOrderInfoService.insertProductOrderInfo(productOrderInfo));
	}

	/**
	 * 修改产品订单
	 */
	@GetMapping("/edit/{orderId}")
	public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
	{
		ProductOrderInfo productOrderInfo = productOrderInfoService.selectProductOrderInfoById(orderId);
		mmap.put("productOrderInfo", productOrderInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存产品订单
	 */
	@RequiresPermissions("channel:productOrderInfo:edit")
	@Log(title = "产品订单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProductOrderInfo productOrderInfo)
	{		
		return toAjax(productOrderInfoService.updateProductOrderInfo(productOrderInfo));
	}
	
	/**
	 * 删除产品订单
	 */
	@RequiresPermissions("channel:productOrderInfo:remove")
	@Log(title = "产品订单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(productOrderInfoService.deleteProductOrderInfoByIds(ids));
	}
	
}
